﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.AnalyticsReportService2Ref;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.BillingServiceRef;
    using WMS6.Web.UserControls;

    public class BillingLoadDetailRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F15641;
        protected GridView gvBillingLoadDetailFrom;
        protected GridView gvBillingLoadDetailTo;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnDueFromTo;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnPara;
        protected HtmlInputButton htmlbtnReport;
        protected Label lblAllTotalAmount;
        protected Label lblAllTotalAmountText;
        protected Label lblBillingLoadList;
        protected Label lblMsg;
        protected LinkButton lnkbtnPrintPaymentBill;
        protected LinkButton lnkbtnPrintReceivableBill;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        protected HtmlTableCell tdlnkbtnPrintPaymentBill;
        protected HtmlTableCell tdlnkbtnPrintReceivableBill;
        private decimal totalAmount;
        protected UpdatePanel up1;

        private void BindData2BillingLoadDetailList(BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(billingLoadDetailRptQueryEntity.CurrentPage);
            DataSet ds = AnalyticsReportService2ClientProxy.GetInstance().GetBillingLoadDetailRptDataSet(billingLoadDetailRptQueryEntity);
            if (this.hdnDueFromTo.Value == "DueFrom")
            {
                this.gvBillingLoadDetailFrom.Visible = true;
                base.BindData2GridView(this.gvBillingLoadDetailFrom, ds);
            }
            else
            {
                this.gvBillingLoadDetailTo.Visible = true;
                base.BindData2GridView(this.gvBillingLoadDetailTo, ds);
            }
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
            billingLoadDetailRptQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "EXPORT";
            string currentPageIndex = billingLoadDetailRptQueryEntity.CurrentPage;
            billingLoadDetailRptQueryEntity.CurrentPage = "0";
            try
            {
                using (DataSet ds = AnalyticsReportService2ClientProxy.GetInstance().GetBillingLoadDetailRptDataSet(billingLoadDetailRptQueryEntity))
                {
                    if (this.hdnDueFromTo.Value == "DueFrom")
                    {
                        base.Export2Excel("PrintBillingLoadDetailRpt.xls", "15641", this.gvBillingLoadDetailFrom, ds);
                    }
                    else
                    {
                        base.Export2Excel("PrintBillingLoadDetailRpt.xls", "15641", this.gvBillingLoadDetailTo, ds);
                    }
                }
            }
            finally
            {
                billingLoadDetailRptQueryEntity.IsGetAll = false;
                billingLoadDetailRptQueryEntity.CurrentPage = currentPageIndex;
                this.SetBillingLoadDetailQueryEntity(billingLoadDetailRptQueryEntity);
            }
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
            billingLoadDetailRptQueryEntity.CurrentPage = "0";
            this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
            billingLoadDetailRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
            billingLoadDetailRptQueryEntity.DOC_ID = "";
            billingLoadDetailRptQueryEntity.DOC_TYPE = "";
            billingLoadDetailRptQueryEntity.EXTERNAL_DOC_ID = "";
            billingLoadDetailRptQueryEntity.COST_TYPE = "";
            billingLoadDetailRptQueryEntity.DUE_FROM_TO = "";
            billingLoadDetailRptQueryEntity.IS_HOLIDAY = "";
            billingLoadDetailRptQueryEntity.StartDateTime = "";
            billingLoadDetailRptQueryEntity.EndDateTime = "";
            billingLoadDetailRptQueryEntity.IS_PRINTED = "";
            this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
            if (int.Parse(billingLoadDetailRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                billingLoadDetailRptQueryEntity.CurrentPage = (int.Parse(billingLoadDetailRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
            if (int.Parse(billingLoadDetailRptQueryEntity.CurrentPage) > 0)
            {
                billingLoadDetailRptQueryEntity.CurrentPage = (int.Parse(billingLoadDetailRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
            this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
        }

        private BillingLoadDetailRptQueryEntity GetBillingLoadDetailQueryEntity()
        {
            return (base.PageQueryEntitySession as BillingLoadDetailRptQueryEntity);
        }

        private DataSet GetPrintDataset(GridView gv)
        {
            DataSet printDS;
            try
            {
                int i;
                printDS = new DataSet();
                DataTable dt = new DataTable();
                dt.Columns.Add("CREDENCE_DOC_TYPE", typeof(string));
                dt.Columns.Add("DUE_FROM_TO", typeof(string));
                dt.Columns.Add("COST_TYPE", typeof(string));
                dt.Columns.Add("CHARGE_UNIT", typeof(string));
                dt.Columns.Add("DOC_ID", typeof(string));
                dt.Columns.Add("DOC_TYPE_D", typeof(string));
                dt.Columns.Add("REMARK", typeof(string));
                dt.Columns.Add("EXTERNAL_DOC_ID", typeof(string));
                dt.Columns.Add("WORK_TYPE_D", typeof(string));
                dt.Columns.Add("WORK_CLASS_D", typeof(string));
                dt.Columns.Add("FORKLIFT_DRIVER_D", typeof(string));
                dt.Columns.Add("EQUIPMENT_PROFILE_D", typeof(string));
                dt.Columns.Add("IS_HOLIDAY", typeof(string));
                dt.Columns.Add("CREATED_DATE", typeof(string));
                dt.Columns.Add("COST_TYPE_D", typeof(string));
                dt.Columns.Add("CHARGE_UNIT_D", typeof(string));
                dt.Columns.Add("QUANTITY", typeof(decimal));
                dt.Columns.Add("TOTAL_GROSS_WEIGHT", typeof(decimal));
                dt.Columns.Add("FIXED_RATE", typeof(decimal));
                dt.Columns.Add("BILLING_AMOUNT", typeof(decimal));
                printDS.Tables.Add(dt);
                bool selected = false;
                for (i = 0; i < gv.Rows.Count; i++)
                {
                    if (((CheckBox) gv.Rows[i].FindControl("chbSelect")).Checked)
                    {
                        selected = true;
                        break;
                    }
                }
                int count = 0;
                for (i = 0; i < gv.Rows.Count; i++)
                {
                    if (!((!selected || !((CheckBox) gv.Rows[i].FindControl("chbSelect")).Checked) && selected))
                    {
                        printDS.Tables[0].Rows.Add(new object[0]);
                        printDS.Tables[0].Rows[count]["CREDENCE_DOC_TYPE"] = gv.DataKeys[i]["CREDENCE_DOC_TYPE"].ToString();
                        printDS.Tables[0].Rows[count]["DUE_FROM_TO"] = gv.DataKeys[i]["DUE_FROM_TO"].ToString();
                        printDS.Tables[0].Rows[count]["COST_TYPE"] = gv.DataKeys[i]["COST_TYPE"].ToString();
                        printDS.Tables[0].Rows[count]["CHARGE_UNIT"] = gv.DataKeys[i]["CHARGE_UNIT"].ToString();
                        printDS.Tables[0].Rows[count]["DOC_ID"] = gv.DataKeys[i]["DOC_ID"].ToString();
                        printDS.Tables[0].Rows[count]["DOC_TYPE_D"] = gv.DataKeys[i]["DOC_TYPE_D"].ToString();
                        printDS.Tables[0].Rows[count]["REMARK"] = gv.DataKeys[i]["REMARK"].ToString();
                        printDS.Tables[0].Rows[count]["EXTERNAL_DOC_ID"] = gv.DataKeys[i]["EXTERNAL_DOC_ID"].ToString();
                        printDS.Tables[0].Rows[count]["WORK_TYPE_D"] = gv.DataKeys[i]["WORK_TYPE_D"].ToString();
                        printDS.Tables[0].Rows[count]["WORK_CLASS_D"] = gv.DataKeys[i]["WORK_CLASS_D"].ToString();
                        printDS.Tables[0].Rows[count]["FORKLIFT_DRIVER_D"] = gv.DataKeys[i]["FORKLIFT_DRIVER_D"].ToString();
                        printDS.Tables[0].Rows[count]["EQUIPMENT_PROFILE_D"] = gv.DataKeys[i]["EQUIPMENT_PROFILE_D"].ToString();
                        printDS.Tables[0].Rows[count]["IS_HOLIDAY"] = gv.DataKeys[i]["IS_HOLIDAY"].ToString();
                        printDS.Tables[0].Rows[count]["CREATED_DATE"] = gv.DataKeys[i]["CREATED_DATE"].ToString();
                        printDS.Tables[0].Rows[count]["COST_TYPE_D"] = gv.DataKeys[i]["COST_TYPE_D"].ToString();
                        printDS.Tables[0].Rows[count]["CHARGE_UNIT_D"] = gv.DataKeys[i]["CHARGE_UNIT_D"].ToString();
                        printDS.Tables[0].Rows[count]["QUANTITY"] = gv.DataKeys[i]["QUANTITY"].ToString();
                        printDS.Tables[0].Rows[count]["TOTAL_GROSS_WEIGHT"] = gv.DataKeys[i]["TOTAL_GROSS_WEIGHT"].ToString();
                        printDS.Tables[0].Rows[count]["FIXED_RATE"] = gv.DataKeys[i]["FIXED_RATE"].ToString();
                        printDS.Tables[0].Rows[count]["BILLING_AMOUNT"] = gv.DataKeys[i]["BILLING_AMOUNT"].ToString();
                        count++;
                    }
                }
            }
            finally
            {
            }
            return printDS;
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
                billingLoadDetailRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
            }
        }

        protected void gvBillingLoadDetailFrom_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15641", this.gvBillingLoadDetailFrom);
        }

        protected void gvBillingLoadDetailFrom_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if ((((Label) e.Row.FindControl("lblAmount")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblAmount")).Text))
                {
                    this.totalAmount += decimal.Parse(((Label) e.Row.FindControl("lblAmount")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblAllTotalAmountText.Text = double.Parse(this.totalAmount.ToString()).ToString();
            }
        }

        protected void gvBillingLoadDetailFrom_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
                billingLoadDetailRptQueryEntity.SortField = e.SortExpression;
                if (billingLoadDetailRptQueryEntity.SortDirection == "ASC")
                {
                    billingLoadDetailRptQueryEntity.SortDirection = "DESC";
                }
                else if (billingLoadDetailRptQueryEntity.SortDirection == "DESC")
                {
                    billingLoadDetailRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        protected void gvBillingLoadDetailTo_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15641", this.gvBillingLoadDetailTo);
        }

        protected void gvBillingLoadDetailTo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if ((((Label) e.Row.FindControl("lblAmount")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblAmount")).Text))
                {
                    this.totalAmount += decimal.Parse(((Label) e.Row.FindControl("lblAmount")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblAllTotalAmountText.Text = double.Parse(this.totalAmount.ToString()).ToString();
            }
        }

        protected void gvBillingLoadDetailTo_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
                billingLoadDetailRptQueryEntity.SortField = e.SortExpression;
                if (billingLoadDetailRptQueryEntity.SortDirection == "ASC")
                {
                    billingLoadDetailRptQueryEntity.SortDirection = "DESC";
                }
                else if (billingLoadDetailRptQueryEntity.SortDirection == "DESC")
                {
                    billingLoadDetailRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        protected void lnkbtnPrintPaymentBill_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet ds = this.GetPrintDataset(this.gvBillingLoadDetailTo);
                if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
                {
                    this.Session["PrintBillingLoadDetailPayment"] = ds;
                    BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
                    string date = string.IsNullOrEmpty(billingLoadDetailRptQueryEntity.StartDateTime) ? "" : Convert.ToDateTime(billingLoadDetailRptQueryEntity.StartDateTime).ToString("yyyy-MM-dd");
                    date = date + " 至 " + (string.IsNullOrEmpty(billingLoadDetailRptQueryEntity.EndDateTime) ? "" : Convert.ToDateTime(billingLoadDetailRptQueryEntity.EndDateTime).ToString("yyyy-MM-dd"));
                    string workClass = string.Empty;
                    string employeeID = string.Empty;
                    string ownerID = string.Empty;
                    if (!string.IsNullOrEmpty(billingLoadDetailRptQueryEntity.WORK_CLASS.Replace("LIKE", "").Replace("'", "").Replace("%", "")))
                    {
                        WorkClassInfo workClassInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(billingLoadDetailRptQueryEntity.WORK_CLASS.Replace("LIKE", "").Replace("'", "").Replace("%", "").Trim(), "WORK_CLASS") as WorkClassInfo;
                        if (workClassInfo != null)
                        {
                            workClass = workClassInfo.Descr;
                        }
                    }
                    if (!string.IsNullOrEmpty(billingLoadDetailRptQueryEntity.EMPLOYEE_ID.Replace("LIKE", "").Replace("'", "").Replace("%", "")))
                    {
                        EmployeeInfo employeeInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(billingLoadDetailRptQueryEntity.EMPLOYEE_ID.Replace("LIKE", "").Replace("'", "").Replace("%", "").Trim(), "EMPLOYEE") as EmployeeInfo;
                        if (employeeInfo != null)
                        {
                            employeeID = employeeInfo.EmployeeName;
                        }
                    }
                    if (!string.IsNullOrEmpty(billingLoadDetailRptQueryEntity.OWNER_ID.Replace("LIKE", "").Replace("'", "").Replace("%", "")))
                    {
                        TradePartnerInfo ownerInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(billingLoadDetailRptQueryEntity.OWNER_ID.Replace("LIKE", "").Replace("'", "").Replace("%", "").Trim(), "TRADE_PARTNER") as TradePartnerInfo;
                        if (ownerInfo != null)
                        {
                            ownerID = ownerInfo.Company;
                        }
                    }
                    string para = workClass + "/" + employeeID + "," + ownerID + "," + date;
                    this.hdnPara.Value = para;
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>popPrintBillPayment();</script>", false);
                    this.UpdateBillingCredenceInfos(ds);
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        protected void lnkbtnPrintReceivableBill_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet ds = this.GetPrintDataset(this.gvBillingLoadDetailFrom);
                if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
                {
                    this.Session["PrintBillingLoadDetailReceive"] = ds;
                    BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = this.GetBillingLoadDetailQueryEntity();
                    string date = string.IsNullOrEmpty(billingLoadDetailRptQueryEntity.StartDateTime) ? "" : Convert.ToDateTime(billingLoadDetailRptQueryEntity.StartDateTime).ToString("yyyy-MM-dd");
                    date = date + " 至 " + (string.IsNullOrEmpty(billingLoadDetailRptQueryEntity.EndDateTime) ? "" : Convert.ToDateTime(billingLoadDetailRptQueryEntity.EndDateTime).ToString("yyyy-MM-dd"));
                    string ownerID = string.Empty;
                    if (!string.IsNullOrEmpty(billingLoadDetailRptQueryEntity.OWNER_ID.Replace("LIKE", "").Replace("'", "").Replace("%", "")))
                    {
                        TradePartnerInfo ownerInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(billingLoadDetailRptQueryEntity.OWNER_ID.Replace("LIKE", "").Replace("'", "").Replace("%", "").Trim(), "TRADE_PARTNER") as TradePartnerInfo;
                        if (ownerInfo != null)
                        {
                            ownerID = ownerInfo.Company;
                        }
                    }
                    string para = ownerID + "," + date;
                    this.hdnPara.Value = para;
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>popPrintBillReceive();</script>", false);
                    this.UpdateBillingCredenceInfos(ds);
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity = new BillingLoadDetailRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    billingLoadDetailRptQueryEntity.DOC_ID = this.PreviousPage.OrderID;
                    billingLoadDetailRptQueryEntity.DOC_TYPE = this.PreviousPage.OrderType;
                    billingLoadDetailRptQueryEntity.EXTERNAL_DOC_ID = this.PreviousPage.ExternalOrderID;
                    billingLoadDetailRptQueryEntity.COST_TYPE = this.PreviousPage.CostType;
                    billingLoadDetailRptQueryEntity.DUE_FROM_TO = this.PreviousPage.DueFromTo;
                    billingLoadDetailRptQueryEntity.IS_HOLIDAY = this.PreviousPage.IsHoliday;
                    billingLoadDetailRptQueryEntity.OWNER_ID = this.PreviousPage.OwnerID;
                    billingLoadDetailRptQueryEntity.EMPLOYEE_ID = this.PreviousPage.ForkliftDriverID;
                    billingLoadDetailRptQueryEntity.WORK_CLASS = this.PreviousPage.WorkClass;
                    billingLoadDetailRptQueryEntity.StartDateTime = this.PreviousPage.StartDate;
                    billingLoadDetailRptQueryEntity.EndDateTime = this.PreviousPage.EndDate;
                    billingLoadDetailRptQueryEntity.IS_PRINTED = this.PreviousPage.IsPrint;
                    this.hdnDueFromTo.Value = this.PreviousPage.FromTo;
                }
                else
                {
                    billingLoadDetailRptQueryEntity.DOC_ID = "";
                    billingLoadDetailRptQueryEntity.DOC_TYPE = "";
                    billingLoadDetailRptQueryEntity.EXTERNAL_DOC_ID = "";
                    billingLoadDetailRptQueryEntity.COST_TYPE = "";
                    billingLoadDetailRptQueryEntity.DUE_FROM_TO = "";
                    billingLoadDetailRptQueryEntity.IS_HOLIDAY = "";
                    billingLoadDetailRptQueryEntity.OWNER_ID = "";
                    billingLoadDetailRptQueryEntity.EMPLOYEE_ID = "";
                    billingLoadDetailRptQueryEntity.WORK_CLASS = "";
                    billingLoadDetailRptQueryEntity.StartDateTime = "";
                    billingLoadDetailRptQueryEntity.EndDateTime = "";
                    billingLoadDetailRptQueryEntity.IS_PRINTED = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            billingLoadDetailRptQueryEntity.IsGetAll = false;
            billingLoadDetailRptQueryEntity.CurrentPage = "0";
            billingLoadDetailRptQueryEntity.PageSize = this.gvBillingLoadDetailFrom.PageSize.ToString();
            billingLoadDetailRptQueryEntity.SortField = " DOC_TYPE";
            billingLoadDetailRptQueryEntity.SortDirection = "ASC";
            if (this.hdnDueFromTo.Value == "DueFrom")
            {
                this.PagerFooter.PageSize = this.gvBillingLoadDetailFrom.PageSize;
                this.lnkbtnPrintPaymentBill.Visible = false;
            }
            else
            {
                this.PagerFooter.PageSize = this.gvBillingLoadDetailTo.PageSize;
                this.lnkbtnPrintReceivableBill.Visible = false;
            }
            this.SetBillingLoadDetailQueryEntity(billingLoadDetailRptQueryEntity);
            this.BindData2BillingLoadDetailList(billingLoadDetailRptQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                base.InitAnalyticsReportGridview(this.gvBillingLoadDetailFrom);
                base.InitAnalyticsReportGridview(this.gvBillingLoadDetailTo);
                this.LoadData();
            }
        }

        private void SetBillingLoadDetailQueryEntity(BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity)
        {
            base.PageQueryEntitySession = billingLoadDetailRptQueryEntity;
        }

        private void UpdateBillingCredenceInfos(DataSet ds)
        {
            List<BillingCredenceInfo> billingCredenceInfos = new List<BillingCredenceInfo>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                BillingCredenceInfo billingCredenceInfo = new BillingCredenceInfo {
                    CredenceType = ds.Tables[0].Rows[i]["CREDENCE_DOC_TYPE"].ToString(),
                    DocID = ds.Tables[0].Rows[i]["DOC_ID"].ToString(),
                    DueFromTo = ds.Tables[0].Rows[i]["DUE_FROM_TO"].ToString(),
                    CostType = ds.Tables[0].Rows[i]["COST_TYPE"].ToString(),
                    ChargeUnit = ds.Tables[0].Rows[i]["CHARGE_UNIT"].ToString(),
                    FixedRate = decimal.Parse(ds.Tables[0].Rows[i]["FIXED_RATE"].ToString()),
                    Remark = ds.Tables[0].Rows[i]["REMARK"].ToString(),
                    BillingAmount = decimal.Parse(ds.Tables[0].Rows[i]["BILLING_AMOUNT"].ToString())
                };
                billingCredenceInfos.Add(billingCredenceInfo);
            }
            if (billingCredenceInfos.Count > 0)
            {
                BillingServiceClientProxy.GetInstance().UpdateBillingCredencePrintDate(billingCredenceInfos);
            }
        }

        public BillingLoadDetailRptQuery PreviousPage
        {
            get
            {
                return (BillingLoadDetailRptQuery) base.PreviousPage;
            }
        }
    }
}

